package ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

public class CustomerLogin extends JPanel {
	private JLabel lblWelcomeCustomer;
	private JLabel lblPleaseEnter;
	private JLabel lblLoginId;
	private JLabel lblPassword;
	private JLabel lblUserIcon;
	private JTextField pfPassword;
	private JButton btnLogin;
	private JLabel lblXA9;
	private JLabel lblLogo;
	private JTextField tfLoginId;

	// private int accountnumberCustomer;
	// private int passwordCustomer;

	public CustomerLogin() {
		setBackground(UIManager.getColor("Label.background"));
		setLayout(null);

		lblWelcomeCustomer = new JLabel("Welcome Customer!");
		lblWelcomeCustomer.setOpaque(true);
		lblWelcomeCustomer
				.setBackground(UIManager.getColor("Label.background"));
		lblWelcomeCustomer.setHorizontalAlignment(SwingConstants.CENTER);
		lblWelcomeCustomer.setForeground(Color.BLACK);
		lblWelcomeCustomer.setFont(new Font("Eurostile", Font.BOLD, 24));
		lblWelcomeCustomer.setBounds(0, 94, 735, 28);
		add(lblWelcomeCustomer);

		lblPleaseEnter = new JLabel(
				"Please enter login details to enter the system");
		lblPleaseEnter.setHorizontalAlignment(SwingConstants.CENTER);
		lblPleaseEnter.setForeground(Color.BLACK);
		lblPleaseEnter.setFont(new Font("Eurostile", Font.PLAIN, 16));
		lblPleaseEnter.setBounds(0, 128, 735, 16);
		add(lblPleaseEnter);

		lblLoginId = new JLabel("LoginID:");
		lblLoginId.setFont(new Font("Eurostile", Font.PLAIN | Font.BOLD, 13));
		lblLoginId.setBounds(354, 156, 200, 28);
		add(lblLoginId);

		lblPassword = new JLabel("Password:");
		lblPassword.setFont(new Font("Eurostile", Font.PLAIN | Font.BOLD, 13));
		lblPassword.setBounds(354, 205, 200, 28);
		add(lblPassword);

		btnLogin = new JButton("Login");
		btnLogin.setFont(new Font("Eurostile", Font.BOLD, 13));
		btnLogin.setBounds(349, 267, 155, 35);
		add(btnLogin);

		lblXA9 = new JLabel("\u00A92013 CBS HA.IT (Gruppe XA-9)\t\t ");
		lblXA9.setForeground(UIManager.getColor("Button.darkShadow"));
		lblXA9.setBackground(UIManager.getColor("Button.darkShadow"));
		lblXA9.setHorizontalAlignment(SwingConstants.CENTER);
		lblXA9.setFont(new Font("Eurostile", Font.PLAIN, 11));
		lblXA9.setBounds(0, 423, 735, 50);
		add(lblXA9);

		pfPassword = new JTextField();
		pfPassword.setFont(new Font("Eurostile", Font.PLAIN, 13));
		pfPassword.setForeground(UIManager.getColor("PasswordField.inactiveForeground"));
		pfPassword.setBounds(349, 227, 155, 35);
		add(pfPassword);
		pfPassword.setColumns(10);

		tfLoginId = new JTextField();
		tfLoginId.setFont(new Font("Eurostile", Font.PLAIN, 13));
		tfLoginId.setForeground(UIManager
				.getColor("PasswordField.inactiveForeground"));
		tfLoginId.setBounds(349, 178, 155, 35);
		add(tfLoginId);
		tfLoginId.setColumns(10);

		lblUserIcon = new JLabel("");
		lblUserIcon.setIcon(new ImageIcon(
				"/Users/martinotto-sidelmann/Desktop/user.png"));
		lblUserIcon.setBounds(180, 124, 236, 264);
		add(lblUserIcon);

		lblLogo = new JLabel("");
		lblLogo.setIcon(new ImageIcon(
				"/Users/martinotto-sidelmann/Desktop/Zombium.png"));
		lblLogo.setBounds(530, 12, 200, 70);
		add(lblLogo);

	}

	public int getLoginIdCustomer() {
		try {
			return Integer.parseInt(tfLoginId.getText().trim());
		} catch (NumberFormatException e) {
			return -1;
		}

	}

	public int getPasswordCustomer() {
		try {
			return Integer.parseInt(pfPassword.getText().trim());
		} catch (NumberFormatException e) {
			return -1;
		}

	}

	public JButton getBtnLogin() {
		return btnLogin;
	}

	public void clearFields() {
		pfPassword.setText("");
		tfLoginId.setText("");
	}
	
	public void addActionListener(ActionListener l) {

		btnLogin.addActionListener(l);
	}
}
